import {
  Injectable,
  NestModule,
  MiddlewareConsumer,
  Module,
  Logger,
} from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Log } from '../../entities/log.entity';
import { LogService } from './log.service';
import { LogController } from './log.controller';
import { LoggingInterceptor } from './interceptors/logging.interceptor';

@Module({
  imports: [TypeOrmModule.forFeature([Log])],
  controllers: [LogController],
  providers: [
    LogService,
    {
      provide: APP_INTERCEPTOR,
      useClass: LoggingInterceptor,
    },
  ],
  exports: [LogService],
})
export class LogModule implements NestModule {
  private readonly logger = new Logger(LogModule.name);

  configure(consumer: MiddlewareConsumer) {
    this.logger.log('LogModule已初始化，日志拦截器已生效');
  }
}